`
SunSteven
  • 浏览: 48432 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

设计模式与源码

阅读更多
最近在看JBPM4.4的源码,一直有一种想法,把Tomcat,Spring,Structs,Ext,Hibernate的源码中的23种设计模式进行整理出来,便于部门内学习。把设计的理论结合到源码中进行。

今天先看一下模板模式
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.jpdl.internal.activity;

import org.w3c.dom.Element;

import org.jbpm.jpdl.internal.xml.JpdlParser;
import org.jbpm.pvm.internal.model.ActivityImpl;
import org.jbpm.pvm.internal.util.TagBinding;
import org.jbpm.pvm.internal.util.XmlUtil;
import org.jbpm.pvm.internal.xml.Parse;
import org.jbpm.pvm.internal.xml.Parser;

/**
* @author Tom Baeyens
*/
public abstract class JpdlBinding extends TagBinding {
 
  public JpdlBinding(String tagName) {
    super(tagName, null, null);
  }

  public abstract Object parseJpdl(Element element, Parse parse, JpdlParser parser);

  public final Object parse(Element element, Parse parse, Parser parser) {
    return parseJpdl(element, parse, (JpdlParser) parser);
  }

  public void parseName(Element element, ActivityImpl activity, Parse parse) {
    String name = XmlUtil.attribute(element, "name", isNameRequired() ? parse : null);
   
    if (name!=null) {
      // basic name validation
      if (name.length()==0) {
        parse.addProblem(XmlUtil.errorMessageAttribute(element, "name", name, "is empty"), element);
      }
      activity.setName(name);
    }
  }

  public boolean isNameRequired() {
    return true;
  }
}


父类中这个方法  public abstract Object parseJpdl(Element element, Parse parse, JpdlParser parser);

在子类中实现,但在父类中已经进行使用。

/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jbpm.jpdl.internal.activity;

import org.jbpm.jpdl.internal.xml.JpdlParser;
import org.jbpm.pvm.internal.model.ScopeElementImpl;
import org.jbpm.pvm.internal.task.TaskDefinitionImpl;
import org.jbpm.pvm.internal.xml.Parse;
import org.w3c.dom.Element;

/**
* @author Tom Baeyens
*/
public class TaskBinding extends JpdlBinding {

  private static final String TAG = "task";

  public TaskBinding() {
    super(TAG);
  }

  public Object parseJpdl(Element element, Parse parse, JpdlParser parser) {
    TaskActivity taskActivity = new TaskActivity();

    ScopeElementImpl scopeElement = parse.contextStackFind(ScopeElementImpl.class);
    TaskDefinitionImpl taskDefinition = parser.parseTaskDefinition(element, parse, scopeElement);
    taskActivity.setTaskDefinition(taskDefinition);
   
    return taskActivity;
  }
}
分享到:
评论

相关推荐

    C#设计模式与源码,高手必修

    源码文件《设计模式源码(C#).rar》提供了书中所讲解的设计模式的C#实现,这为读者提供了实际操作和学习的平台,通过阅读和调试源码,能够更直观地理解设计模式的运用和效果。 总之,《C#设计模式与源码》是一本深入...

    设计模式实例源码

    这个压缩包文件名为“23种设计模式示例源码”,暗示其中包含了解决23种经典设计模式的具体实现代码,这对于初学者或者希望深入理解设计模式的开发者来说是一份宝贵的资源。下面将对这23种设计模式进行详细解释。 1....

    C++设计模式源码C++设计模式源码

    本资料包含了C++实现的设计模式源码,旨在帮助开发者深入理解和应用这些模式。 一、单例模式(Singleton) 单例模式确保一个类只有一个实例,并提供一个全局访问点。在C++中,可以通过私有化构造函数和静态成员函数...

    设计模式 带源码 设计模式 带源码 设计模式 带源码

    设计模式 带源码设计模式 带源码设计模式 带源码设计模式 带源码设计模式 带源码设计模式 带源码设计模式 带源码

    Android源码设计模式解析与实战.pdf

    《Android 源码设计模式解析与实战》不仅分析了Android源代码的设计模式,更结合实例演示了如何使用这些设计模式。看这本书,既能学到如何分析、学习Android源代码,又能提高自己架构设计水平 《Android 源码设计...

    研磨设计模式源码

    《研磨设计模式源码》是一份非常宝贵的资源,它提供了设计模式的实践代码,帮助开发者深入理解并应用这些模式。设计模式是软件工程中经过长期实践总结出来的一套通用解决方案,它们描述了在特定场景下如何解决常见...

    深入浅出设计模式附书源码Java版源码

    深入浅出设计模式附书源码Java版源代码,是面向Java开发者的宝贵资源,旨在帮助他们理解和实践各种设计模式。这本书籍的源代码提供了实际的示例,使得学习过程更具互动性和实践性。 设计模式的核心思想是将常见的...

    中文版_源码设计模式解析与实战.pdf

    《中文版_源码设计模式解析与实战.pdf》是一本专为Android开发者设计的进阶书籍,它深入探讨了设计模式在实际开发中的应用,并结合Android的源码进行了详细的解析。这本书不仅涵盖了基础的设计模式概念,还通过丰富...

    java设计模式刘伟源码

    Java设计模式是软件开发中的重要概念,它是一种在特定情境下解决常见...通过研究这些源码,你可以更好地理解设计模式的精髓,提升自己的编程技能,从而在实际项目中更好地应用这些原则和模式,编写出更高质量的代码。

    c#设计模式源码

    C#设计模式源码是专门为C#程序员提供的一种学习资源,它包含了多种经典设计模式的实际应用示例。通过这些源码,开发者可以深入理解设计模式的核心理念,提高代码的可读性、可维护性和复用性。 一、单例模式...

    P级阵地项目(设计模式与游戏完美开发)源码

    《设计模式与游戏完美开发》一书中的源码主要基于Unity3D引擎,适用于5.5及更高版本,旨在帮助开发者理解如何运用设计模式来优化游戏开发过程。在这个项目中,我们将探讨Unity3D与设计模式的结合,以及在游戏开发中...

    设计模式源码.zip

    本压缩包"设计模式源码.zip"包含了基于C#的工程化实现和扩展的设计模式源代码,旨在帮助开发者在实际项目中提升设计能力。 首先,让我们深入探讨设计模式的分类。设计模式主要分为三类:创建型模式、结构型模式和...

    Head First 设计模式 JAVA源码

    《HeadFirst设计模式》(中文版)共有14章,每章都介绍了几个设计模式,完整地涵盖了四人组版本全部23个设计模式。前言先介绍这本书的用法;第1章到第11章陆续介绍的设计模式为Strategy、Observer、Decorator、...

    Csharp设计模式源码

    "Csharp设计模式源码"这个主题聚焦于使用C#语言实现设计模式,旨在帮助开发者不仅掌握编程技能,更理解软件设计的思想,从而提高代码的可维护性、复用性和扩展性。下面我们将深入探讨几个核心的设计模式及其C#实现。...

    Android源码设计模式解析与实战

    Android源码设计模式解析与实战 Android源码设计模式解析与实战 Android源码设计模式解析与实战 Android源码设计模式解析与实战 Android源码设计模式解析与实战 Android源码设计模式解析与实战 Android源码设计模式...

    iOS 设计模式及源码实现

    本资源“iOS 设计模式及源码实现”深入探讨了iOS开发中的关键设计模式,并提供了实际的Objective-C源码示例。 1. **单例模式**:单例模式确保一个类只有一个实例,并提供全局访问点。在iOS中,常用于管理像网络请求...

    GOF设计模式源码

    自己学习整理的设计模式源码,一共22个有源码 其中一个解释器模式不常用,暂时没必要看,都是自己手动编写和调试通过的,供想要学习设计模式的同学下载学习,每个模式均有先关说明和注释

    Android源码设计模式解析与实战.PDF(完整版)

    根据提供的文件信息“Android源码设计模式解析与实战.PDF(完整版)”,本文将深入探讨其中的关键知识点,包括但不限于Android开发中常见的设计模式及其在实际项目中的应用案例。 ### Android设计模式概述 #### 设计...

    ActionScript 3.0设计模式源码

    **ActionScript 3.0 设计模式源码详解** 在软件开发中,设计模式是一种解决常见问题的经验总结,它提供了一种在特定上下文中高效、可重用的解决方案。ActionScript 3.0(AS3)是Adobe Flash Platform的主要编程语言...

    23种设计模式源码

    23种设计模式的源码,并且有流程图..................................................................................................................

Global site tag (gtag.js) - Google Analytics