Android Open Source - markj Viewer Xml Mapper






From Project

Back to project page markj.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project markj listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.markjmind.mobile.api.android.controller;
/* w ww . j a v a 2  s.  c o m*/
import java.io.IOException;
import java.util.HashMap;

import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import android.app.Activity;
import android.app.Application;
import android.app.Dialog;
import android.content.Context;
import android.util.Log;

import com.markjmind.mobile.api.android.util.JwTextUtils;
import com.markjmind.mobile.api.android.xml.JwXmlLoader;
/**
 * start : 2013.11.17<br>
 * <br>
 * 
 * @author ???
 * @version 2013.11.17
 */
public class ViewerXmlMapper {
  public HashMap<String, ViewerInfo> viewers = new HashMap<String, ViewerInfo>();
  private Application app;
  
  public ViewerXmlMapper(Application app){
    this.app = app;
  }
  
  
  public void load(int R_raw_xml){
    ViewerXmlHandler viewerXmlHandler = new ViewerXmlHandler();
    JwXmlLoader xml = new JwXmlLoader(viewerXmlHandler);
    try {
      xml.readXml(app, R_raw_xml);
      Log.d("JwViewer", viewerXmlHandler.getLog());
    } catch (ParserConfigurationException e) {
      throw new JwMapperException("viewer xml??? parsing??? ???? ?????.", e);
    } catch (SAXException e) {
      throw new JwMapperException("viewer xml??? parsing??? ???? ?????.", e);
    } catch (IOException e) {
      throw new JwMapperException("viewer xml??? ???????? ???? ?????.", e);
    }
  }
  
  public void add(String name, ViewerInfo viewerInfo){
    viewers.put(name, viewerInfo);
  }
  
  public void add(ViewerInfo viewerInfo){
    viewers.put(viewerInfo.id, viewerInfo);
  }
  
  public void add(String id, int R_layout_id, String desc, JwViewer jwViewer, Class viewerClass){
    ViewerInfo info = new ViewerInfo(id, R_layout_id, jwViewer, desc, viewerClass);
    add(info);
  }
  
  /**
   * ????? ?????
   * @param id
   * @param context
   * @return
   */
  public JwViewer getViewer(String id, Activity context){
    ViewerInfo info = viewers.get(id);
    return info.getViewer(context);
  }
  public JwViewer getViewer(String id, Dialog context){
    ViewerInfo info = viewers.get(id);
    return info.getViewer(context);
  }
  
  
  public void setInstanceOption(String id, int opt){
    ViewerInfo info = viewers.get(id);
    info.setInstanceOption(opt);
  }
  
  private class ViewerXmlHandler extends DefaultHandler{
      private StringBuilder text = new StringBuilder();
      private StringBuffer log = new StringBuffer();
      
      public String getLog(){
        return log.toString();
      }
      
        @Override
        public void startElement(String uri, String localName, String qName,Attributes attributes){
          if("viewer".equals(localName)){
            String layoutName = attributes.getValue("layout");
            String id = JwTextUtils.getEmpty(attributes.getValue("id"), layoutName);
            String[] otpInstance ={"new","save"};
            int instance = JwTextUtils.getContainsIndex(attributes.getValue("instance"), otpInstance,  1);
            int layout_id = JwStringID.getLayoutID(layoutName, app);
            
            Class vclass=null;
            if(layoutName==null || layoutName.trim().length()==0){
              throw new JwMapperException("viewer Node?? layout ?????? ???? ?????.");
            }
        try {
          vclass = Class.forName(attributes.getValue("class"));
        } catch (ClassNotFoundException e) {
          throw new JwMapperException("["+attributes.getValue("class")+"] ?????? ???? ????.", e);
        }
        
        log.append("add Viewer[id:"+id+"  layout:"+layoutName+"  class:"+vclass.getName()+"]\n");
            ViewerInfo info = new ViewerInfo(id, layout_id, null, "", vclass);
            if(instance==0){
              instance = JwViewer.INSTANCE_NEW;
            }
            info.setInstanceOption(instance);
            add(info);
          }
            text.setLength(0);
        }
        @Override
        public void endElement(String uri, String localName, String qName){
          text.setLength(0);
        }

        
        @Override
        public void characters(char[] ch, int start, int length)throws SAXException {
          text.append(ch,start,length);
        }
  }
  
  private class ViewerInfo{
    public String id;
    public int layoutId;
    public JwViewer viewer;
    public String desc;
    public Class viewerClass;
    public int instance;
    
    public ViewerInfo(String id, int layoutId, JwViewer viewer, String desc, Class viewerClass){
      this.id = id;
      this.layoutId = layoutId;
      this.viewer = viewer;
      this.desc = desc;
      this.viewerClass = viewerClass;
      setInstanceOption(JwViewer.INSTANCE_SAVE);
    }
    
    public JwViewer getViewer(Object context){
      if(instance == JwViewer.INSTANCE_NEW){
        viewer=null;
        return  newViewerInstanceObj(context);
      }else{
        if(viewer==null){
          viewer = newViewerInstanceObj(context);
          return  newViewerInstanceObj(context);
        }
      }
      viewInit(viewer, context);
      return viewer;
    }
    
    private JwViewer newViewerInstanceObj(Object context){
      JwViewer bl = getJwViewer();
      viewInit(bl, context);
      bl.setId(id);
      return bl;
    }
    
    /**
     * ????? ??? ??
     * @param bl
     * @param context
     */
    private void viewInit(JwViewer bl, Object context){
      if(context instanceof Activity){
        bl.init((Activity)context,layoutId);
      }else if(context instanceof Dialog){
        bl.init(((Dialog)context),layoutId);
      }else{
        throw new JwMapperException(viewerClass.getName()+" ?????? ????? ????. ?? Viewer??? context? Activity???? Dialog???? ???? ??? ?????.", null);
      }
      
    }
    
    private JwViewer getJwViewer(){
      try {
        JwViewer bl = (JwViewer)viewerClass.newInstance();
        return bl;
      } catch (InstantiationException e) {
        throw new JwMapperException(viewerClass.getName()+" ?????? ????? ????.", e);
      } catch (IllegalAccessException e) {
        throw new JwMapperException(viewerClass.getName()+"??? ??????? ????.", e);
      }
    }
    public void setInstanceOption(int opt){
      instance = opt;
    }
  }
}




Java Source Code List

com.markjmind.mobile.api.android.controller.JwAsyncTask.java
com.markjmind.mobile.api.android.controller.JwMapperException.java
com.markjmind.mobile.api.android.controller.JwMemberMapper.java
com.markjmind.mobile.api.android.controller.JwStringID.java
com.markjmind.mobile.api.android.controller.JwViewController.java
com.markjmind.mobile.api.android.controller.JwViewerCache.java
com.markjmind.mobile.api.android.controller.JwViewer.java
com.markjmind.mobile.api.android.controller.Jwc.java
com.markjmind.mobile.api.android.controller.OnClickListenerReceiver.java
com.markjmind.mobile.api.android.controller.ViewerXmlMapper.java
com.markjmind.mobile.api.android.exception.JwErrorCode.java
com.markjmind.mobile.api.android.exception.JwException.java
com.markjmind.mobile.api.android.json.JSONMsgString.java
com.markjmind.mobile.api.android.json.JwJOSNTreeArray.java
com.markjmind.mobile.api.android.json.JwJSONReader.java
com.markjmind.mobile.api.android.ui.JwAnimation.java
com.markjmind.mobile.api.android.ui.JwGroup.java
com.markjmind.mobile.api.android.ui.JwMenu.java
com.markjmind.mobile.api.android.ui.JwOnGroupSelect.java
com.markjmind.mobile.api.android.ui.JwTabGroup.java
com.markjmind.mobile.api.android.ui.JwTouchGroupListener.java
com.markjmind.mobile.api.android.ui.JwTouchGroup.java
com.markjmind.mobile.api.android.ui.JwTouchMotionGroupLisener.java
com.markjmind.mobile.api.android.ui.JwTouchMotionGroup.java
com.markjmind.mobile.api.android.ui.drawgraph.GraphBoard.java
com.markjmind.mobile.api.android.ui.drawgraph.GraphSkin.java
com.markjmind.mobile.api.android.ui.drawgraph.HBackLineSkin.java
com.markjmind.mobile.api.android.ui.drawgraph.LineGraphSkin.java
com.markjmind.mobile.api.android.ui.drawgraph.PieGraph.java
com.markjmind.mobile.api.android.ui.drawgraph.RectGraphSkin.java
com.markjmind.mobile.api.android.ui.drawgraph.SimpleStyle.java
com.markjmind.mobile.api.android.ui.drawgraph.TextArraySkin.java
com.markjmind.mobile.api.android.ui.drawgraph.VBackLineSkin.java
com.markjmind.mobile.api.android.ui.graph.Arc.java
com.markjmind.mobile.api.android.ui.graph.BarElement.java
com.markjmind.mobile.api.android.ui.graph.BarLayout.java
com.markjmind.mobile.api.android.ui.graph.Bar.java
com.markjmind.mobile.api.android.ui.graph.IPieSkin.java
com.markjmind.mobile.api.android.ui.graph.LineLayout.java
com.markjmind.mobile.api.android.ui.graph.MeasureLayout.java
com.markjmind.mobile.api.android.ui.graph.PieArcRoundSkin.java
com.markjmind.mobile.api.android.ui.graph.PieLayout.java
com.markjmind.mobile.api.android.ui.graph.PiePercentSkin.java
com.markjmind.mobile.api.android.ui.view.JwBaseDropDown.java
com.markjmind.mobile.api.android.ui.view.JwDropDown.java
com.markjmind.mobile.api.android.ui.view.JwSlidingLayout.java
com.markjmind.mobile.api.android.ui.view.JwWheelView.java
com.markjmind.mobile.api.android.ui.view.StickerListener.java
com.markjmind.mobile.api.android.ui.view.StickerView.java
com.markjmind.mobile.api.android.ui.view.textview.JwTextViewAutoScale.java
com.markjmind.mobile.api.android.ui.view.textview.JwTextViewFonts.java
com.markjmind.mobile.api.android.ui.view.textview.JwTextViewWrapScale.java
com.markjmind.mobile.api.android.ui.wrapper.JwAlertDialog.java
com.markjmind.mobile.api.android.ui.wrapper.JwToast.java
com.markjmind.mobile.api.android.util.JwFile.java
com.markjmind.mobile.api.android.util.JwPreferenceList.java
com.markjmind.mobile.api.android.util.JwPreference.java
com.markjmind.mobile.api.android.util.JwSound.java
com.markjmind.mobile.api.android.util.JwTextUtils.java
com.markjmind.mobile.api.android.util.PhoneInfo.java
com.markjmind.mobile.api.android.util.WebConnection.java
com.markjmind.mobile.api.android.xml.JwDomHandler.java
com.markjmind.mobile.api.android.xml.JwDomLoader.java
com.markjmind.mobile.api.android.xml.JwEditElementHandler.java
com.markjmind.mobile.api.android.xml.JwXmlLoader.java
com.markjmind.mobile.api.android.xml.JwXmlResoure.java
com.markjmind.mobile.api.hub.ArrayJDhub.java
com.markjmind.mobile.api.hub.DBhub.java
com.markjmind.mobile.api.hub.JDhub.java
com.markjmind.mobile.api.hub.Loader.java
com.markjmind.mobile.api.hub.StoreList.java
com.markjmind.mobile.api.hub.Store.java